package com.Pawtrack.info.service.impl;

import java.util.List;
import com.Pawtrack.common.utils.DateUtils;
import com.Pawtrack.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.Pawtrack.info.mapper.PetFenceMapper;
import com.Pawtrack.info.domain.PetFence;
import com.Pawtrack.info.service.IPetFenceService;

/**
 * 电子围栏Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-14
 */
@Service
public class PetFenceServiceImpl implements IPetFenceService 
{
    @Autowired
    private PetFenceMapper petFenceMapper;

    /**
     * 查询电子围栏
     * 
     * @param id 电子围栏主键
     * @return 电子围栏
     */
    @Override
    public PetFence selectPetFenceById(Long id)
    {
        return petFenceMapper.selectPetFenceById(id);
    }

    /**
     * 查询电子围栏列表
     * 
     * @param petFence 电子围栏
     * @return 电子围栏
     */
    @Override
    public List<PetFence> selectPetFenceList(PetFence petFence)
    {
        // 自动设置当前用户ID，确保只能查询自己的数据
        if (petFence != null) {
            petFence.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        }
        return petFenceMapper.selectPetFenceList(petFence);
    }

    /**
     * 新增电子围栏
     * 
     * @param petFence 电子围栏
     * @return 结果
     */
    @Override
    public int insertPetFence(PetFence petFence)
    {
        // 自动设置创建人为当前用户ID
        petFence.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        petFence.setCreateTime(DateUtils.getNowDate());
        return petFenceMapper.insertPetFence(petFence);
    }

    /**
     * 修改电子围栏
     * 
     * @param petFence 电子围栏
     * @return 结果
     */
    @Override
    public int updatePetFence(PetFence petFence)
    {
        // 自动设置更新人为当前用户ID
        petFence.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        petFence.setUpdateTime(DateUtils.getNowDate());
        return petFenceMapper.updatePetFence(petFence);
    }

    /**
     * 批量删除电子围栏
     * 
     * @param ids 需要删除的电子围栏主键
     * @return 结果
     */
    @Override
    public int deletePetFenceByIds(Long[] ids)
    {
        return petFenceMapper.deletePetFenceByIds(ids);
    }

    /**
     * 删除电子围栏信息
     * 
     * @param id 电子围栏主键
     * @return 结果
     */
    @Override
    public int deletePetFenceById(Long id)
    {
        return petFenceMapper.deletePetFenceById(id);
    }
}
